Link to this headingRC4
- Do not use
- Has biases for the first 256 bytes output information.
- It also has biases for all output information.
Used in WEP, TKIP, BitTorrent protocol encryption
Link to this headingSecurity
- The Key Scheduling Algorithm is bad
Link to this headingKey Reuse
you can’t re-use the same RC4 keystream to encrypt two different messages
Link to this headingBit Flip Attacks
Padding Oracle
Link to this headingBit Bias
Here shows the bias for the first 256 bytes
PoC:
= True
= False
=
return
= 100000000 # PyCryptodome ARC4 is faster, so we can push higher trials
= 16
=
= # 128-bit random key
=
=
+= 1
= /
= 0.5
=
= /
=
=
=
=
=
=
RC4 Output:
) )
You can see above that certain positions and bits have up to a 0.20% Bias over 10,000,000,000
Here you can see AES to see the difference in randomness.
AES Output:
) )
Link to this headingFluhrer, Mantin and Shamir attack
- A 16-byte key can be computed from about 960 such keystreams because of the coloration of the outputs
- The usually ways to fix this is dont use the first 3072 bytes of the output
- Don’t concat the IV to the key. Hash them instead.
In [WEP](/Red Team/Wifi/WEP) if the IV is predictable either by a random number generator or other way it makes it easy to figure out the first byte of the keystream. Since RC4 only generates one byte at a time it makes it easy to figure out the next byte and continue down the line.
Link to this headingKlein, Dropping and Hashing
- Reduces the operations needed to find the IV from a few million to 20,000
Link to this headingImplementation
=
#Just a list of 0-255
=
= 0
#
+= +
%= 256
#Swap the index I with the acc index
, = ,
return
= 0
= 0
+= 1
%= 256
+=
%= 256
#Swap the index I with the acc index
, = ,
= % 256
=
#print(index, output)
yield
#Generate the s_box from the secret key
=
#print(s_box)
#Generate Keystream from s_box
return
#Test Vectors from https://tools.ietf.org/html/rfc6229
=
= b
+=
assert